﻿<%@ WebHandler Language="C#" Class="ResumeDownload" %>

using System;
using System.Web;

public class ResumeDownload : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        string fileName = context.Request.QueryString["name"] != null ? context.Request.QueryString["name"].ToString() : string.Empty;

        if (!string.IsNullOrEmpty(fileName))
        {
            try
            {
                string filePath = string.Empty;
                filePath = "~/UploadedResume/" + fileName;
                string f = context.Server.MapPath(filePath);

                if (System.IO.File.Exists(f))
                {
                    context.Response.Clear();
                    context.Response.ContentType = "application/octet-stream";
                    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    context.Response.WriteFile(context.Server.MapPath(filePath));
                    context.Response.TransmitFile(context.Server.MapPath(filePath));
                    context.Response.End();
                }
            }
            catch (System.Threading.ThreadAbortException)
            {

            } 
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}